package cian_f_rice;

import java.util.Scanner;

import cian_f_rice.model.DecisionLinesEvent;
import cian_f_rice.model.Line;
import cian_f_rice.view.DecisionLinesGUI;

/**
 * This implementation of Decision Lines is built off of the sample provided by Professor Heineman because
 * my GUI bugged the living daylights out of me.
 */

/**
 * Launching code that retrieves (m,n) from user keyboard input and then launches the window
 * in which the decisionLines are visible.
 *  
 * @author heineman
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// retrieve decision lines (N)
		int n = -1;
		while (n < 3 || n > 8) {
			System.out.println("Enter number of decision lines to use [3-8]: ");
			try { 
				n = Integer.valueOf(sc.nextLine());
			} catch (Exception e) {
				// announce error below
			}
			
			if (n < 3 || n > 8) {
				System.err.println("Please enter an integer between 3 and 8");
			}
		}
		
		// retrieve number of rounds (M)
		int m = -1;
		while (m < 3 || m > 8) {
			System.out.println("Enter number of rounds [3-8]: ");
			try { 
				m = Integer.valueOf(sc.nextLine());
			} catch (Exception e) {
				//
			}
			
			if (m < 3 || m > 8) {
				System.err.println("Please enter an integer between 3 and 8");
			}
		}
		
		DecisionLinesEvent model = new DecisionLinesEvent (n);
		model.setNumRounds(m);
		
		// Create n line objects.
		for (int l = 0; l < n; l++)
		{
			Line line = new Line(l);
			model.lines.add(line);
		}
		
		DecisionLinesGUI app = new DecisionLinesGUI (model);
		app.setVisible (true);		
	}
}

